<?php
require_once('./class/CommentEvenement.php');
require_once('./class/Adherent.php');
require_once('./class/Evenement.php');

switch (@$_GET['action']) {
    default:
        echo _COMMENTAIRE_EVENEMENT_;
    break;

    case "addForm":
        $c = new CommentEvenement();
        $c->setIdEvenement($_GET['id_evenement']);
        echo $c->getAddForm();
        break;

    case "doAdd":
        $c = new CommentEvenement();
        $c->setIdIndividu($_POST['id_individu']);
        $c->setIdEvenement($_POST['id_evenement']);
        $c->setCommentaire($_POST['commentaire']);
        $c->addOrModify();
        echo _COMMENTAIRE_." "._ADDED_;
        break;

    case "modifyForm":
        $n = CommentEvenement::getComment($_GET['id']);
        echo $n->getModifyForm();
        break;

    case "doModify":
        $c = new CommentEvenement();
        $c->setIdCommentaire($_POST['id_commentaire']);
        $c->setIdIndividu($_POST['id_individu']);
        $c->setIdEvenement($_POST['id_evenement']);
        $c->setCommentaire($_POST['commentaire']);
        $c->addOrModify();
        echo _COMMENTAIRE_." "._MODIFIED_;
        break;
         
    case "list":
        $comment_array = CommentEvenement::getAllComment($_GET['id']);
        $html = '<table class="tablesorter">
							 <thead>
							 		<th>'._ID_COMMENTAIRE_.'</th>
									<th>'._ADHERENT_.'</th>
									<th>'._DATE_.'</th>
									<th>'._COMMENTAIRE_.'</th>
									<th>'._EDIT_.'</th>
									<th>'._DELETE_.'</th>
								</thead>
								<tbody>';
        $i = 0;
        foreach($comment_array as $c) {
            $a = Adherent::getIndividu($c->getIdIndividu());
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
									<td>'.$c->getIdCommentaire().'</td>
									<td>'.$a->getNom().' '.$a->getPrenom().'</td>
									<td>'.$c->getDate().'</td>
									<td>'.$c->getCommentaire().'</Td>
									<td><a href="?module=commentEvenement&action=modifyForm&id='.$c->getIdCommentaire().'">'._EDIT_.'</a></td>
									<td><a href="?module=commentEvenement&action=delete&id='.$c->getIdCommentaire().'">'._DELETE_.'</a></td>
									</tr>';
        }
        $html .= '</tbody></table>';
        $html .= '<a href="?module=commentEvenement&action=addForm&id_evenement='.$_GET['id'].'">'._ADD_.'</a></br>';
        echo $html;
        break;

    case "delete":
        $c = CommentEvenement::getComment($_GET['id'])	;
        $c->delete();
        echo _COMMENTAIRE_.' '._DELETED_;
        break;
}
?>
